//
//  InfoViewController.m
//  HRJiWei
//
//  Created by zsj1992 on 16/12/13.
//  Copyright © 2016年 bjhj. All rights reserved.
//

#import "InfoViewController.h"
#import "XLForm.h"
#import "HJCustomReportCell.h"
#import "FileUploadViewController.h"
@interface InfoViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation InfoViewController
- (IBAction)back:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)complete:(id)sender {

    NSArray * arr =  [self.form localValidationErrors:self];
    NSLog(@"%@",arr);

    
    NSDictionary * dic = [self.form formValues];
    NSLog(@"%@",dic);
}

XLFormRowDescriptor * rowSex;
XLFormRowDescriptor * rowRank;
-(instancetype)init{

    if (self = [super init]) {
        
        
       
        XLFormDescriptor *form = [XLFormDescriptor formDescriptor];//创建表单
        XLFormSectionDescriptor *section1 = [XLFormSectionDescriptor formSectionWithTitle:@"被举报人信息"];  //创建区
        

        //被举报人-Section
        
        //被举报姓名
        XLFormRowDescriptor * row1 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toName" rowType:XLFormRowDescriptorTypeReport];
        [row1.cellConfig setValue:@"被举报人姓名" forKey:@"textField.placeholder"];

        
        
        
        
        
        
        row1.required = YES;
        row1.requireMsg = @"傻逼,这里还没填";
        row1.value = @"ssds";
        
        
        
        
        
        
        
        
        
        //被举报姓名
        XLFormRowDescriptor * row2 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toSex" rowType:XLFormRowDescriptorTypeReport];
        [row2.cellConfig setValue:@"被举报人性别" forKey:@"textField.placeholder"];
        [row2.cellConfig setValue:@(NO) forKey:@"indicator.hidden"];

        [row2.cellConfig setValue:@(NO) forKey:@"textField.userInteractionEnabled"];
        row2.value = @"男";
        rowSex = row2;
        
        
        //被举报姓名
        XLFormRowDescriptor * row3 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toCompany" rowType:XLFormRowDescriptorTypeReport];
        [row3.cellConfig setValue:@"被举报人单位" forKey:@"textField.placeholder"];

        //被举报姓名
        XLFormRowDescriptor * row4 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toPosition" rowType:XLFormRowDescriptorTypeReport];
        [row4.cellConfig setValue:@"职务" forKey:@"textField.placeholder"];

        //被举报姓名
        XLFormRowDescriptor * row5 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toPolitical" rowType:XLFormRowDescriptorTypeReport];
        [row5.cellConfig setValue:@"政治面貌" forKey:@"textField.placeholder"];

        //被举报姓名
        XLFormRowDescriptor * row6 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toArea" rowType:XLFormRowDescriptorTypeReport];
        [row6.cellConfig setValue:@"所属地" forKey:@"textField.placeholder"];

        //被举报姓名
        XLFormRowDescriptor * row7 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toAddress" rowType:XLFormRowDescriptorTypeReport];
        [row7.cellConfig setValue:@"单位地址或地址" forKey:@"textField.placeholder"];

        //被举报姓名
        XLFormRowDescriptor * row8 = [XLFormRowDescriptor formRowDescriptorWithTag:@"toLevel" rowType:XLFormRowDescriptorTypeReport];
        [row8.cellConfig setValue:@"级别" forKey:@"textField.placeholder"];
        [row8.cellConfig setValue:@(NO) forKey:@"indicator.hidden"];
        [row8.cellConfig setValue:@(NO) forKey:@"textField.userInteractionEnabled"];
        rowRank = row8;
        
        //每次创建完一个cell后都需要
        [section1 addFormRow:row1];
        [section1 addFormRow:row2];
        [section1 addFormRow:row3];
        [section1 addFormRow:row4];
        [section1 addFormRow:row5];
        [section1 addFormRow:row6];
        [section1 addFormRow:row7];
        [section1 addFormRow:row8];

        
    /***************************************************************************/
    /***************************************************************************/
    /***************************************************************************/
        
        
        XLFormSectionDescriptor *section2 = [XLFormSectionDescriptor formSectionWithTitle:@"举报人信息"];  //创建区
        
        
        //被举报人-Section
        
        //被举报姓名
        XLFormRowDescriptor * row11 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromName" rowType:XLFormRowDescriptorTypeReport];
        [row11.cellConfig setValue:@"姓名" forKey:@"textField.placeholder"];
        row11.required = YES;
        row11.requireMsg = @"举报人姓名不能为空";
        
        
        
        
        
        //被举报姓名
        XLFormRowDescriptor * row12 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromSex" rowType:XLFormRowDescriptorTypeReport];
        [row12.cellConfig setValue:@"性别" forKey:@"textField.placeholder"];
        [row12.cellConfig setValue:@(NO) forKey:@"indicator.hidden"];
        [row12.cellConfig setValue:@(NO) forKey:@"textField.userInteractionEnabled"];

        
        
        //被举报姓名
        XLFormRowDescriptor * row13 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromNational" rowType:XLFormRowDescriptorTypeReport];
        [row13.cellConfig setValue:@"民族" forKey:@"textField.placeholder"];
        
        //被举报姓名
        XLFormRowDescriptor * row14 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromPolitical" rowType:XLFormRowDescriptorTypeReport];
        [row14.cellConfig setValue:@"政治面貌" forKey:@"textField.placeholder"];
        
        //被举报姓名
        XLFormRowDescriptor * row15 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromMobile" rowType:XLFormRowDescriptorTypeReport];
        [row15.cellConfig setValue:@"手机号码" forKey:@"textField.placeholder"];
        row15.required = YES;
        row15.requireMsg = @"举报人手机号码不能为空";

        
        
        
        //被举报姓名
        XLFormRowDescriptor * row16 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromIdno" rowType:XLFormRowDescriptorTypeReport];
        [row16.cellConfig setValue:@"身份证号" forKey:@"textField.placeholder"];
        
        //被举报姓名
        XLFormRowDescriptor * row17 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromArea" rowType:XLFormRowDescriptorTypeReport];
        [row17.cellConfig setValue:@"所属地" forKey:@"textField.placeholder"];
        
        //被举报姓名
        XLFormRowDescriptor * row18 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromPost" rowType:XLFormRowDescriptorTypeReport];
        [row18.cellConfig setValue:@"邮政编码" forKey:@"textField.placeholder"];
        //被举报姓名
        XLFormRowDescriptor * row19 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromAddress" rowType:XLFormRowDescriptorTypeReport];
        [row19.cellConfig setValue:@"住址" forKey:@"textField.placeholder"];
        //被举报姓名
        XLFormRowDescriptor * row20 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromCompany" rowType:XLFormRowDescriptorTypeReport];
        [row20.cellConfig setValue:@"工作单位" forKey:@"textField.placeholder"];
        //被举报姓名
        XLFormRowDescriptor * row21 = [XLFormRowDescriptor formRowDescriptorWithTag:@"fromPosition" rowType:XLFormRowDescriptorTypeReport];
        [row21.cellConfig setValue:@"职务" forKey:@"textField.placeholder"];
        
        //每次创建完一个cell后都需要
        [section2 addFormRow:row11];
        [section2 addFormRow:row12];
        [section2 addFormRow:row13];
        [section2 addFormRow:row14];
        [section2 addFormRow:row15];
        [section2 addFormRow:row16];
        [section2 addFormRow:row17];
        [section2 addFormRow:row18];
        [section2 addFormRow:row19];
        [section2 addFormRow:row20];
        [section2 addFormRow:row21];

        

        
        
        
        
        
        //    创建完所有cell后还要
        
        [form addFormSection:section1];
        [form addFormSection:section2];

        self.form = form;
        
        
    
        
    }

    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    
    self.tableView.frame = CGRectMake(0, 64,self.tableView.frame.size.width ,self.tableView.frame.size.height-64);
    
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
//    self.tableView.tableHeaderView = self.headView;
//    self.footerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 50, [UIScreen mainScreen].bounds.size.width, 50);
//    [self.view addSubview:self.footerView];

}


//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
//    view.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1];
//    return view;
//    
//}




-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UILabel * lblHeader = [[UILabel alloc]init];
    lblHeader.textColor = [UIColor darkGrayColor];
    lblHeader.font = [UIFont systemFontOfSize:15];
    
    
    if (section==0) {
        lblHeader.text = @"      被举报人资料";

        
    }else{
        
        lblHeader.text = @"      实名举报人资料";
    }

    return lblHeader;
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0||section==1) {
        return 20;
    }
    return CGFLOAT_MIN;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"点击了");
    
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (indexPath.section==0) {
        
        if (indexPath.row==1){
            UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"被举报人性别"                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
            //添加Button
            [alertController addAction: [UIAlertAction actionWithTitle: @"男" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //处理点击拍照

                rowSex.value = @"男";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowSex.value = @"女";
                [self updateFormRow:rowSex];

            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
            
            [self presentViewController: alertController animated: YES completion: nil];
        }else if (indexPath.row==7){//职级
            
            
            UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"被举报人职级"                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
            //添加Button
            [alertController addAction: [UIAlertAction actionWithTitle: @"处级" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //处理点击拍照
                
                rowRank.value = @"处级";
                [self updateFormRow:rowRank];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"乡(科)级" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowRank.value = @"乡(科)级";
                [self updateFormRow:rowRank];
                
            }]];[alertController addAction: [UIAlertAction actionWithTitle: @"科级以下干部" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowRank.value = @"科级以下干部";
                [self updateFormRow:rowRank];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
            
            [self presentViewController: alertController animated: YES completion: nil];

            
            
            
        }
        
    }else if (indexPath.section==1){
    
        
        if (indexPath.row==1) {
            
            UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"被举报人性别"                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
            //添加Button
            [alertController addAction: [UIAlertAction actionWithTitle: @"男" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //处理点击拍照
                
                rowSex.value = @"男";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowSex.value = @"女";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
            
            [self presentViewController: alertController animated: YES completion: nil];

        }else if (indexPath.row==9){
            UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"被举报人性别"                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
            //添加Button
            [alertController addAction: [UIAlertAction actionWithTitle: @"男" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //处理点击拍照
                
                rowSex.value = @"男";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowSex.value = @"女";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowSex.value = @"女";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                //处理点击从相册选取
                
                rowSex.value = @"女";
                [self updateFormRow:rowSex];
                
            }]];
            [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
            
            [self presentViewController: alertController animated: YES completion: nil];

        }
    }
}




-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section==1) {
        
        UIView * view = [[UIView alloc]init];
        
        UIButton * btnNext = [[UIButton alloc]init];
        btnNext.backgroundColor = [UIColor colorWithRed:155/255.0 green:22/255.0 blue:3/255.0 alpha:1];
        [btnNext setTitle:@"下一步" forState:(UIControlStateNormal)];
        [btnNext addTarget:self action:@selector(btnNextClick) forControlEvents:(UIControlEventTouchUpInside)];
        [view addSubview:btnNext];
        
        [btnNext mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view).offset(20);
            make.right.equalTo(view).offset(-20);
            make.centerY.equalTo(view);
            make.height.mas_equalTo(40);
        }];
        
        return view;

    }
    return nil;
}

//点击了下一步
-(void)btnNextClick{
    
    
    NSArray * arr =  [self.form localValidationErrors:self];
    
    
    NSLog(@"%@",arr);
    
    
    if (arr.count>0) {
        
        NSError * error = arr[0];
        NSDictionary * userInfo = error.userInfo;

        [Tool ShowpromptWithMsg:userInfo[@"NSLocalizedDescription"]];
    
        return;

    }
    
    
    

    
    NSDictionary * dic = [self.form formValues];

    HJReport * report = [HJReport mj_objectWithKeyValues:dic];
    
    report.reportStyle = self.report.reportStyle;
    
    report.reportTitle = self.report.reportTitle;
    
    report.categoryId = self.report.categoryId;
    
    report.categoryName = self.report.categoryName;
    
    report.reportContent = self.report.reportContent;
    
    
    
    
    FileUploadViewController * fileVc = [[FileUploadViewController alloc]init];
    fileVc.report = report;
    [self.navigationController pushViewController:fileVc animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==1) {
        
        return 60;

    }else{
    
        return 0.01;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
